<?php
	class Order extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			if (!isset($_SESSION)) {
			    session_start();
			    session_regenerate_id();
			}
			$this->load->helper("url");
			
		}
		public function index()
		{
			$data=array();
			
			
				$type=0;
				if(isset($_REQUEST['type']))
					$type=$_REQUEST['type'];
				$data['type']=$type;
				
				$data['action']='list_order';
				$this->load->model("morder");
				$data['list_order']=$this->morder->list_order($type);
				$lorder=array();
				
				$lorder[0]=0;
				$lorder[1]=0;
				$lorder[2]=0;
				$lorder[3]=0;
				$lorder[-1]=0;
				
				$order=$this->morder->get_orders();
				foreach ($order as $value){
					$lorder[$value['status']]=$value['sl'];
				}
				$data['lorder']=$lorder;
			$this->load->view("order_template", $data);
		}
		public function order_detail()
		{
			$data=array();
				$oid=$_REQUEST['oid'];
				$data['oid']=$oid;
				
				$data['action']='order_detail';
				$this->load->model("morder");
				$data['order_detail']=$this->morder->get_order_detail($oid);
				$lorder=array();
				
				$lorder[0]=0;
				$lorder[1]=0;
				$lorder[2]=0;
				$lorder[3]=0;
				$lorder[-1]=0;
				
				$order=$this->morder->get_orders();
				foreach ($order as $value){
					$lorder[$value['status']]=$value['sl'];
				}
				$data['lorder']=$lorder;
				
			$this->load->view("order_template", $data);
		}
		public function saveMemo(){
			$oid=trim($_REQUEST['oid']);
			$amemo=trim($_REQUEST['amemo']);
			$this->load->model("morder");
			$this->morder->saveMemo($oid,$amemo);
			echo '<script>
						window.location.assign("'.$_SESSION['linkorder'].'");
						</script>';
		}
		public function changtype(){
			$oid=trim($_REQUEST['oid']);
			$type=trim($_REQUEST['type']);
			$this->load->model("morder");
			$this->morder->changtype($oid,$type);
			echo '<script>
						window.location.assign("'.$_SESSION['linkorder'].'");
						</script>';
		}
	}
?>